﻿using WikiMaml.Renderers;
using WikiPlex;
using Xunit;
using Xunit.Extensions;

namespace WikiMaml.Facts.Renderers
{
    public class TableRendererFacts
    {
        public class CanExpand
        {
            [Theory]
            [InlineData(ScopeName.TableBegin)]
            [InlineData(ScopeName.TableEnd)]
            [InlineData(ScopeName.TableCell)]
            [InlineData(ScopeName.TableCellHeader)]
            [InlineData(ScopeName.TableRowBegin)]
            [InlineData(ScopeName.TableRowEnd)]
            [InlineData(ScopeName.TableRowHeaderBegin)]
            [InlineData(ScopeName.TableRowHeaderEnd)]
            [InlineData(MamlScopeName.TableHeaderBegin)]
            [InlineData(MamlScopeName.TableHeaderEnd)]
            public void Should_be_able_to_resolve_the_scope_name(string scopeName)
            {
                var renderer = new TableRenderer();

                bool result = renderer.CanExpand(scopeName);

                Assert.True(result);
            }
        }

        public class Expand
        {
            [Theory]
            [InlineData(ScopeName.TableBegin, "<table>")]
            [InlineData(ScopeName.TableEnd, "</table>")]
            [InlineData(ScopeName.TableCell, "</entry><entry>")]
            [InlineData(ScopeName.TableCellHeader, "</entry><entry>")]
            [InlineData(ScopeName.TableRowBegin, "<row><entry>")]
            [InlineData(ScopeName.TableRowEnd, "</entry></row>")]
            [InlineData(ScopeName.TableRowHeaderBegin, "<row><entry>")]
            [InlineData(ScopeName.TableRowHeaderEnd, "</entry></row>")]
            [InlineData(MamlScopeName.TableHeaderBegin, "<tableHeader>")]
            [InlineData(MamlScopeName.TableHeaderEnd, "</tableHeader>")]
            public void Should_resolve_the_scope_correctly(string scopeName, string expectedResult)
            {
                var renderer = new TableRenderer();

                string actualResult = renderer.Expand(scopeName, string.Empty, x => x, x => x);

                Assert.Equal(expectedResult, actualResult);
            }

            [Fact]
            public void Should_return_content_for_invalid_scope_name()
            {
                var renderer = new TableRenderer();

                string result = renderer.Expand("foo", "in", x => x, x => x);

                Assert.Equal("in", result);
            }
        }
    }

}
